/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ch.repit.aglaja.client.contacts;

import ch.repit.rwt.client.Bento;
import ch.repit.rwt.client.BentoStatus;
import ch.repit.rwt.client.ui.BentoListPage;
import ch.repit.rwt.client.ui.Page;
import java.util.Map;

/**
 *
 * @author tc149752
 */

public class TagListPage extends BentoListPage
{

    public TagListPage(Page topPage, BentoStatus... status)
    {
        super (topPage, TagDef.TYPE, status);
        setTitle("Tags");

        // set the columns
        super.addColumn("Nom du tag",  TagDef.ATTR_NAME, true);
        super.addColumn("Description", TagDef.ATTR_DESCRIPTION, false);
        super.addColumn("Status", "_status", false); // false bkz lazy...
        super.addColumn("Nombre d'adresses", "_size", false); // false bkz lazy...
    }



    @Override
    protected boolean formatObject(Bento bento, Map formatedValue) {
        formatedValue.put("_status", bento.getStatus().name());
        formatedValue.put("_size", (bento.get(TagDef.ATTR_ADDRESSES).getStringList()==null)?"0":
            (""+bento.get(TagDef.ATTR_ADDRESSES).getStringList().size()) );

        return super.formatObject(bento, formatedValue);
    }



    @Override
    protected void onRowClicked(Bento bento, String columnsAttributeName) {
        getPageNav().displayPage(new TagDetailsPage(bento.getRef()));
    }

}

